* This file should be used with the data in "Stuck_in_the_Middle_data.dta".
* It includes the model presented in Figure 1.

* Main text model
clear all
use "Stuck_in_the_Middle_data.dta"
set more off
log using "Stuck_in_the_Middle_log", replace

* Replication of Figure 1:
set more off
clogit cvote dis_lr i.party if cyear==1, group(resp_id)
estimate store model1_08
clogit cvote dis_lr i.party if cyear==2, group(resp_id)
estimate store model1_11
clogit cvote dis_lr i.party if cyear==3, group(resp_id) 
estimate store model1_15

coefplot (model1_08, label(2008) ciopts(recast(rcap) color(gs7)) lcolor(gs7) acolor(gs7)  mcolor(gs7) msymbol(T)) ///
(model1_11, label(2011) ciopts(recast(rcap) color(black)) lcolor(black) acolor(black)  mcolor(black)) ///
(model1_15, label(2015) ciopts(recast(rcap) color(gs11)) lcolor(gs11) acolor(gs11)  mcolor(gs11)), grid(no) ///
graphregion(color(white)) bgcolor(white) xtitle(Log-odd Coefficients) xline(0, lcolor(black) lpattern(dash)) ///
coeflabels(*dis_lr = "Left-Right" 2.party="Tories' Valence" 3.party="NDP's Valence" 4.party="BQ's Valence" 5.party="Greens' Valence")  ///
title("Canada", c(black) j(right)) leg(r(1)) graphregion(margin(b+0 l+30 r+0)) xscale(range(-3 3)) xlab(-3.5(.5)3)
graph save Graph "canada1.gph" ,replace 
graph export "canada1.png", as(png) replace

* Germany:
set more off
clogit cvote dis_lr i.party if cyear==4, group(resp_id) or
estimate store model1_09
clogit cvote dis_lr i.party if cyear==5, group(resp_id) or
estimate store model1_13
clogit cvote dis_lr i.party if cyear==6, group(resp_id) or
estimate store model1_17

coefplot (model1_09, label(2009) ciopts(recast(rcap) color(gs7)) lcolor(gs7) acolor(gs7)  mcolor(gs7) msymbol(T)) ///
(model1_13, label(2013) ciopts(recast(rcap) color(black)) lcolor(black) acolor(black)  mcolor(black)) ///
(model1_17, label(2017) ciopts(recast(rcap) color(gs11)) lcolor(gs11) acolor(gs11)  mcolor(gs11)), ///
graphregion(color(white)) bgcolor(white) xtitle(Log-odd Coefficients) xline(0, lcolor(black) lpattern(dash)) grid(no) ///
coeflabels(*dis_lr = "Left-Right" 2.party="CDU's Valence" 3.party="SPD's Valence" 4.party="Left's Valence" 5.party="Green's Valence" 6.party="AfD's Valence")  ///
title("Germany", c(black) j(left)) leg(r(1)) graphregion(margin(b+0 l+30 r+0)) xscale(range(-3 3)) xlab(-3.5(.5)3)
graph save Graph "germany1.gph" ,replace 
graph export "germany1.png", as(png) replace

* UK:
set more off
clogit cvote dis_lr i.party if cyear==7, group(resp_id) or
estimate store model1_10
clogit cvote dis_lr i.party if cyear==8, group(resp_id) or
estimate store model1_15
clogit cvote dis_lr i.party if cyear==9, group(resp_id) or
estimate store model1_17

coefplot (model1_10, label(2010) ciopts(recast(rcap) color(gs8)) lcolor(gs8) acolor(gs8)  mcolor(gs8) msymbol(T)) ///
(model1_15, label(2015) ciopts(recast(rcap) color(black)) lcolor(black) acolor(black)  mcolor(black)) ///
(model1_17, label(2017) ciopts(recast(rcap) color(gs10)) lcolor(gs10) acolor(gs10)  mcolor(gs10)), ///
graphregion(color(white)) bgcolor(white) xtitle(Log-odd Coefficients) xline(0, lcolor(black) lpattern(dash)) grid(no) ///
coeflabels(*dis_lr = "Left-Right" 2.party="Tories' Valence" 3.party="Labour's Valence" 4.party="SNP's Valence" 5.party="Green's Valence" 6.party="UKIP's Valence")  ///
title("United Kingdom", c(black) j(right)) leg(r(1)) graphregion(margin(b+0 l+30 r+0)) xscale(range(-3 3)) xlab(-4.5(.5)3)
graph save Graph "UK1.gph" ,replace 
graph export "UK1.png", as(png) replace

* Finland:
set more off

clogit cvote dis_lr i.party if cyear==10, group(resp_id) or
estimate store model1_07
clogit cvote dis_lr i.party if cyear==11, group(resp_id) or
estimate store model1_11
clogit cvote dis_lr i.party if cyear==12, group(resp_id) or
estimate store model1_15

coefplot (model1_07, label(2007) ciopts(recast(rcap) color(gs8)) lcolor(gs8) acolor(gs8)  mcolor(gs8) msymbol(T)) ///
(model1_11, label(2011) ciopts(recast(rcap) color(black)) lcolor(black) acolor(black)  mcolor(black)) /// 
(model1_15, label(2015) ciopts(recast(rcap) color(gs10)) lcolor(gs10) acolor(gs10)  mcolor(gs10)), ///
graphregion(color(white)) bgcolor(white) xtitle(Log-odd Coefficients) xline(0, lcolor(black) lpattern(dash)) grid(no) ///
coeflabels(*dis_lr = "Left-Right" 2.party="KOK's Valence" 3.party="SDP's Valence" 4.party="VAS's Valence" 5.party="Green's Valence" ///
6.party="PS's Valence") drop(7.party 8.party)  ///
title("Finland", c(black) j(left)) leg(r(1)) graphregion(margin(b+1 l+25 r+1)) xscale(range(-3 1)) xlab(-3.5(.5)1)
graph save Graph "finland1.gph" ,replace 
graph export "finalnd1.png", as(png) replace

* Combine figures to create Figure 1
graph combine "germany1.gph" ///
"UK1.gph" ///
"finland1.gph" ///
"canada1.gph", ///
col(2) comm altshrink graphregion(color(white)) 
graph save Graph "Figure_1.gph" ,replace 
graph export "Figure_l.png", as(png) replace

log close
